package com.qms.tubu.fragment.account;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.transition.Slide;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qms.tubu.R;
import com.qms.tubu.application.TubuApplication;
import com.qms.tubu.bean.AccountBean;
import com.qms.tubu.fragment.BaseFragment;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Mad on 2015/7/23.
 */
public class DrawerLoginFragment extends BaseFragment implements TubuApplication.OnAccountChangeListener{
    private TextView mUsernameText,mSignatureText;
    private CircleImageView mPortraitImage;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootView=inflater.inflate(R.layout.fragment_drawer_login,container,false);
        mUsernameText= (TextView) rootView.findViewById(R.id.drawer_login_username_text);
        mSignatureText= (TextView) rootView.findViewById(R.id.drawer_login_signature_text);
        mPortraitImage= (CircleImageView) rootView.findViewById(R.id.drawer_login_portrait_image);
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
        getTubuApplication().addChangeListener(this);
    }
    private void initData(){
        AccountBean account=getTubuApplication().getAccount();
        if(account==null)
            return;
        mUsernameText.setText(account.getNickname());
        mSignatureText.setText(account.getSignature());
        Glide.with(this).load(account.getHeadimgurl())
                .error(R.drawable.default_big_head_portrait)
                .centerCrop()
                .into(mPortraitImage);
    }
    @Override
    public void onDestroyView() {
        getTubuApplication().removeChangeListener(this);
        super.onDestroyView();
    }

    @Override
    public void onDataChanged() {
        initData();
    }

    @Override
    public void onSignStateChanged(boolean signState) {

    }
}
